package commandAction;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.TreeMap;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import robotCross.TipMatcher;
import abbot.finder.BasicFinder;
import abbot.finder.ComponentNotFoundException;
import abbot.finder.MultipleComponentsFoundException;
import abbot.finder.matchers.ClassMatcher;
import abbot.tester.JTreeLocation;
import abbot.tester.JTreeTester;
import abbot.tester.Robot;
import abbot.util.AWTFixtureHelper;

import com.sun.corba.se.spi.activation.Server;
import com.supermap.data.Dataset;
import com.supermap.data.DatasetVector;
import com.supermap.data.Datasource;
import com.supermap.desktop.ui.UICommonToolkit;
import com.supermap.desktop.ui.controls.TreeNodeData;
import com.supermap.desktop.ui.controls.WorkspaceTree;

import command.Command;
import command.SearchMap;
import command.SearchType;

public class ActionWorkspaceTree extends Action {
	ArrayList<TreeNode> treeNodes = new ArrayList<TreeNode>();
	WorkspaceTree tree = UICommonToolkit.getWorkspaceManager()
			.getWorkspaceTree();

	@Override
	public Object action(Command cmd) {
		// TODO Auto-generated method stub
		// 查找目标节点
		treeNodes = ActionTree.findTreeNodes(tree, cmd.searchMap);
		if (treeNodes == null || treeNodes.size() == 0)
			return null;
		//选中节点
		ActionTree.selectTreeNodes(treeNodes);
		//右键菜单
		if (cmd.getMenuItem() != null) {
			TreePath treePath = new TreePath(
					((DefaultMutableTreeNode) treeNodes.get(treeNodes.size() - 1))
							.getPath());
			new JTreeTester().actionSelectPopupMenuItem(tree,
					new JTreeLocation(treePath), cmd.getMenuItem());
		}
		return null;
	}
}
